<template>
	<view class="head">
		<view class="inputClass">
			<view>余额:</view>
			<view>{{accountMoney}} 币</view>
		</view>
		
		<view class="inputClass" style="margin-top: 40rpx;">
			<view>提现额度:</view>
			<u-input v-model="value" :type="type" :border="border" :clearable="false" />
		</view>
		<view style="margin-top: 60rpx;">
			<u-button type="success" @click="getMonetNow">立即提现</u-button>
		</view>
		<view style="margin-top: 20rpx;">
			<u-button @click="everyMoney">提现所有</u-button>
		</view>
		<u-toast ref="uToast" position="center" />
		<u-modal v-model="show" :content="content" @confirm="confirm" :show-cancel-button="showBut"></u-modal>
		<u-modal v-model="msg" :content="messages" @confirm="confirmMsg" :show-cancel-button="showBut"></u-modal>
	</view>
</template>

<script>
	import {withDrawals} from '@/api/order.js'
	export default {
		created() {
			const res = uni.getStorageSync('userInfo')
			this.accountMoney = res.account_money
		},
		data() {
			return {
				msg:false,
				messages:"",
				content:"",
				showBut:true,
				show:false,
				value:"",
				type:"text",
				border:true,
				accountMoney:"",
			}
		},
		methods: {
			everyMoney(){
				this.value = this.accountMoney
			},
			// 提现申请
			getMonetNow(){
				this.show = true
				this.content = "是否确认提现"
			},
			async confirm(){
				let data = {
					account:this.value
				}
				const res = await withDrawals(data)
				if(res.data.code === 200){
					this.$refs.uToast.show({
						title:res.data.data,
						type:"success"
					})
					return
				}
				if(res.data.msg === "未实名,请先实名再提现"){
					this.msg = true
					this.messages = res.data.msg
					return
				}else{
					this.$refs.uToast.show({
						title:res.data.msg,
						type:"error"
					})
				}
			},
			// 未实名弹窗警告
			confirmMsg(){
				uni.navigateTo({
					url:"/subPages/subUser/realName/index"
				})
			}
		}
	}
</script>

<style lang="scss">
.head{
	padding: 20rpx;
	width: 80%;
	box-shadow: rgba(99, 99, 99, 0.2) 0px 2px 8px 0px;
	border-radius: 20rpx;
	margin: 120rpx auto;
	color: #c9c9c9;
}
.uInput{
	margin-top: 40rpx;
}
.inputClass{
	display: flex;
	justify-content: space-between;
	align-items: center;
}

</style>
